
import { Debtor } from "../../../../typings/types/debtor"
import { Litigation } from "../../../../typings/types/litigation"
import { getCourtNoticeDetailApi, getFinalCaseDetailApi, getOpenCourtNoticeDetailApi, getRegisterDetailApi } from "../api/shesu"
import { LitigationVM } from "../litigation/litigationVM"

export class LitigationDetailViewModel implements LitigationVM.ViewModelInterface<string, Debtor.BaseInfoList[]> {
  constructor() {
  }
  processLocalDataForScene(scene: LitigationVM.Scene | string, local: any): Debtor.BaseInfoList[] {
    switch (scene) {
      case LitigationVM.Scene.countEquityFreeze:
        {
          return this.processEquityFreezeListDatas(local)
        }
        break
      case LitigationVM.Scene.countAssistanceUnfreeze:
        {
          return this.processAssistanceUnfreezeListDatas(local)
        }
        break
      default: return []
    }
  }
  async loadDataForScene(scene: LitigationVM.Scene, id: string, successCallback: (res: Debtor.BaseInfoList[]) => void, finallyCallback: (() => void) = () => { }) {
    wx.showLoading({
      title: ''
    })
    try {
      let tmp: Debtor.BaseInfoList[] = []
      switch (scene) {
        case LitigationVM.Scene.openCourtNotice:
          const res = await getOpenCourtNoticeDetailApi(id)
          if (res.content) {
            console.log(res.content)
            tmp = this.processOpenCourtListDatas(res.content)
          }
          break
        case LitigationVM.Scene.courtNotice:
          const res_c = await getCourtNoticeDetailApi(id)
          if (res_c.content) {
            console.log(res_c.content)
            tmp = this.processCourtListDatas(res_c.content)
          }
          break
        case LitigationVM.Scene.register:
          const res_r = await getRegisterDetailApi(id)
          if (res_r.content) {
            console.log(res_r.content)
            tmp = this.processRegisterListDatas(res_r.content)
          }

          break
        case LitigationVM.Scene.finalCase:
          const res_f = await getFinalCaseDetailApi(id)
          if (res_f.content) {
            console.log(res_f.content)
            tmp = this.processFinalCaseListDatas(res_f.content)
          }

          break
        case LitigationVM.Scene.countEquityFreeze:
          break
        case LitigationVM.Scene.countAssistanceUnfreeze:
          break
        case LitigationVM.Scene.bankruptcy:
          break
        case LitigationVM.Scene.dishonestExecutor:
          break
        case LitigationVM.Scene.litigationInfo:
          break
        case LitigationVM.Scene.subordinateDebtor:
          break
        default: break

      }
      if (tmp.length > 0) {
        successCallback(tmp)
      }

    } finally {
      wx.hideLoading()
      finallyCallback()
    }

  }

  processOpenCourtListDatas(content: Litigation.OpenCourtNoticeDetail) {

    let tmp: Debtor.BaseInfoList[] = [

      { title: '案号', val: content.caseNo, isShowLine: true },
      { title: '案由', val: content.caseReason, isShowLine: true },
      { title: '原告/上诉人', val: content.prosecutor, sectitle: '被告/被上诉人', secval: content.defendant, isShowLine: true },
      { title: '法院', val: content.executeGov, sectitle: '法庭', secval: content.executeUnite },
      { title: '承办部门', val: content.undertakeDepartment, sectitle: '审判长/主审人', secval: content.chiefJudge },
    ]

    return tmp
  }

  processCourtListDatas(content: Litigation.CourtNoticeDetail) {

    let tmp: Debtor.BaseInfoList[] = [

      { title: '公告法院', val: content.court, isShowLine: true },
      { title: '当事人', val: content.litigant, isShowLine: true },
      { title: '上诉人', val: content.prosecutorList, sectitle: '被上诉人', secval: content.defendantList },
      { title: '创建时间', val: content.createdDate, sectitle: '上传时间', secval: content.uploadDate, isShowLine: true },
      { title: '内容', val: content.content, type: "1" },

    ]

    return tmp
  }

  processRegisterListDatas(content: Litigation.RegisterDetail) {

    let tmp: Debtor.BaseInfoList[] = [

      { title: '案号', val: content.caseNo, isShowLine: true },
      { title: '案由', val: content.reason, isShowLine: true },
      { title: '上诉人', val: content.prosecutor, sectitle: '被上诉人', secval: content.appellee, isShowLine: false },
      { title: '第三人', val: content.outsider, isShowLine: true },
      { title: '法院', val: content.court, sectitle: '承办部门', secval: content.department },
      { title: '案件类型', val: content.caseType, sectitle: '案件状态', secval: content.caseStatus, secstyle: 'color:#F04040' },
      { title: '立案时间', val: content.registDate, isShowLine: false },
    ]

    return tmp
  }
  processFinalCaseListDatas(content: Litigation.FinalCaseDetail) {

    let tmp: Debtor.BaseInfoList[] = [

      { title: '被执行人', val: content.caseNo, isShowLine: true },
      { title: '被执行人身份证号码/组织机构代码/统一社会信用代码', val: content.cardNum, isShowLine: true },
      { title: '案号', val: content.caseNo, sectitle: '执行法院', secval: content.courtName, isShowLine: true },
      { title: '执行标的', val: content.execMoney, sectitle: '未履行金额', secval: content.unperfMoney, style: 'color:#F04040', secstyle: 'color:#F04040', valsubfix: '元', secvalsubfix: '元' },
      { title: '立案时间', val: content.regDate, sectitle: '终本时间', secval: content.finalDate },
    ]

    return tmp
  }

  processEquityFreezeListDatas(content: any) {
    let tmp: Debtor.BaseInfoList[] = [

      { title: '执行文书文号', val: content.executionDocNum, isShowLine: true },
      { title: '执行裁定书文号', val: content.executionVerdictNum, isShowLine: true },
      // { title: '被执行人证件号码', val: content.executedPersonDocNum, isShowLine: true },
      { title: '执行事项', val: content.executionMatters, isShowLine: true },
      { title: '企业名称', val: content.companyName },
      { title: '相关企业名称', val: content.scompanyName, isShowLine: true },
      { title: '冻结开始时间', val: content.freezeStartDate, sectitle: '冻结结束时间', secval: content.freezeEndDate, isShowLine: false },
      { title: '公示时间', val: content.publicDate, isShowLine: false },
    ]

    return tmp
  }

  processAssistanceUnfreezeListDatas(content: any) {
    let tmp: Debtor.BaseInfoList[] = [

      { title: '执行文书文号', val: content.executionDocNum, isShowLine: true },
      { title: '执行裁定书文号', val: content.executionVerdictNum, isShowLine: true },
      { title: '解除文书号', val: content.thawDocNo, isShowLine: true },
      { title: '执行事项', val: content.executionMatters, isShowLine: true },
      { title: '企业名称', val: content.companyName },
      { title: '解冻机关', val: content.thawOrgan, isShowLine: true },
      { title: '解除冻结时间', val: content.unFreezeDate, sectitle: '公示时间', secval: content.publicDate, isShowLine: false },
    ]

    return tmp
  }
}